package com.sleepcamel.resteasyConfigurator.view.updateValueStrategies;

import org.eclipse.core.databinding.UpdateValueStrategy;
import org.eclipse.core.databinding.conversion.IConverter;

import com.sleepcamel.rest.domain.JavaClass;

public class ClassToStringUpdateValueStrategy extends UpdateValueStrategy {

	public ClassToStringUpdateValueStrategy() {
		setConverter(new ClassToStringConverter());
	}
}

class ClassToStringConverter implements IConverter{

	@Override
	public Object getFromType() {
		return JavaClass.class;
	}

	@Override
	public Object getToType() {
		return String.class;
	}

	@Override
	public Object convert(Object paramObject) {
		if ( paramObject instanceof JavaClass ){
			return ((JavaClass) paramObject).getName();
		}
		return null;
	}
	
}
